//模拟用户数据库
let user_list = [{
        id: 1,
        username: '啊',
        password: '111'
    },
    {
        id: 2,
        username: '加菲',
        password: '222'
    },
    {
        id: 3,
        username: '小智',
        password: '333'
    }
]

// 判断是不是存在的用户
let fn_index = async(ctx, next) => {
    let username = ctx.request.body.username || '';
    let password = ctx.request.body.password || '';

    let res = user_list.filter(item => {
        return item.username === username && item.password === password
    })

    if (res.length > 0) {
        ctx.body = {
            code: 200,
            data: res[0],
            msg: '登入成功'
        }
    } else {
        ctx.body = {
            code: 404,
            data: null,
            msg: '登入失败'
        }
    }
}

module.exports = {
    'post /login': fn_index
}